
package org.puremvc.as3.multicore.demos.flex.hellopipes.shell.view
{
	import flash.events.Event;
	
	import mx.collections.ArrayCollection;
	
	import org.puremvc.as3.multicore.demos.flex.hellopipes.shell.ApplicationFacade;
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.patterns.mediator.Mediator;
	
	public class HelloPipesShellMediator extends Mediator
	{
		//
		// vars

		//
		// const	
		public static const NAME: String = 'HelloPipesShellMediator';
		
		//
		// instances

		
				
		public function HelloPipesShellMediator( viewComponent: HelloPipesShell )
		{
			super( NAME, viewComponent );
		}

		/**
		 * Register event listeners with the app and its fixed controls.
		 */
		override public function onRegister():void
		{
			//
			// add listener for events dispatched by its view component (shell)
			app.addEventListener( HelloPipesShell.MODULE_INITIALIZED, moduleInitializedHandler );
			app.addEventListener( HelloPipesShell.MODULE_REMOVED, moduleRemovedHandler );
			app.addEventListener( HelloPipesShell.SAY_HELLO_TO_MODULE, sayHelloToModuleHandler );			
		
		}
		
		/**
		 * Application related Notification list.
		 */
		override public function listNotificationInterests():Array
		{
			return [  ];	
		}
		
		/**
		 * Handle notifications.
		 */
		override public function handleNotification( note:INotification ):void
		{

		}
		
		/**
		 * The Application component.
		 */
		private function get app():HelloPipesShell
		{
			return viewComponent as HelloPipesShell;
		}
		
		/**
		 * Update messages which are displayed at shell
		 */		
		public function updateMessages( messages: ArrayCollection):void
		{
			app.showMessagesSendedFromModule( messages );
		}
		
		//--------------------------------------------------------------------------
		//
		// callbacks for handling events dispatch by view component
		//
		//--------------------------------------------------------------------------
			
		private function moduleInitializedHandler( event: Event ):void
		{
			sendNotification( ApplicationFacade.MODULE_ADDED, app.getModule() );
		}					
		
		private function moduleRemovedHandler( event: Event ):void
		{
			sendNotification( ApplicationFacade.MODULE_REMOVED );			
		}

		private function sayHelloToModuleHandler( event: Event ):void
		{
			sendNotification( ApplicationFacade.SEND_MESSAGE_TO_MODULE, 
								"Hello Module, I'm a message sended from shell" );		
		}
			
	}
}